package com.twu.biblioteca;

public class Movie
{
    protected static Movie list[]=seed();
    protected static int total=list.length;

    String name,director;
    int year,rating;

    Movie(String movieName,int movieYear,String movieDirector,int movieRating)
    {
        name=movieName;
        year=movieYear;
        director=movieDirector;
        rating=movieRating;
    }

    protected static boolean isValidRating(int rating)
    {
        return rating>=1&&rating<=10;
    }
    public boolean equals(Object obj)
    {
        if(obj instanceof Movie)
        {
            Movie second=(Movie)obj;
            return this.name.equals(second.name)&&this.year==second.year&&this.director.equals(second.director)&&this.rating==second.rating;
        }
        return false;
    }

    private String rating()
    {
        if(!isValidRating(rating))
            return "NA";
        else
            return ""+rating;
    }

    private void display()
    {
        System.out.printf("%-20s %-8d %-20s %4s",name,year,director,rating());
        System.out.println();
    }

    private static void displayHeader()
    {
        System.out.println("       MOVIE          Year        Director      Rating\n");
    }

    protected static void displayAll()
    {
        displayHeader();
        for(int i=0;i<total;i++)
        {
            list[i].display();
        }
    }

    private static Movie[] seed()
    {
        Movie allMovies[]=new Movie[4];
        allMovies[0]= new Movie("Indiana Jones",1992,"Steven Speilberg",-1);
        allMovies[1]= new Movie("Start Trek",1982,"Steven Speilberg",1);
        allMovies[2]= new Movie("Forrest Gump",1993,"Warren Buffet",10);
        allMovies[3]= new Movie("Fight Club",2004,"Christopher Nolan",8);
        return allMovies;
    }
}
